<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<%
	String context = request.getContextPath();

	String bookName = (String)request.getAttribute("bookName");
	if(bookName == null) bookName = "";
	
	List bookList = (List)request.getAttribute("bookList");
%>

<%@page import="java.util.List"%>
<%@page import="book.Book"%>

<script type="text/javascript">
<!--

function selectAll(thisObj){
	var fidArr = document.getElementsByName("fid");
	if(thisObj.checked){
		for(var i = 0;i<fidArr.length;i++){
			fidArr[i].checked = true;
		}
	}else{
		for(var i = 0;i<fidArr.length;i++){
			fidArr[i].checked = false;
		}
	}
}

function downloadAllTxt(){
	var form = document.forms[0];
	form.action = "<%=context%>/wall.do?action=downloadAllTxt";
	form.submit();
}

function downloadAllChm(){
	var form = document.forms[0];
	form.action = "<%=context%>/wall.do?action=downloadAllChm";
	form.submit();
}

function downloadChm(){
	var fidArr = document.getElementsByName("fid");
	var selectIndex = 0;
	for(var i = 0;i<fidArr.length;i++){
		if(fidArr[i].checked){
			selectIndex ++;
		}
	}
	if(selectIndex==0){
		alert("请选择记录");
		return false;
	}
	
	var form = document.forms[0];
	form.action = "<%=context%>/wall.do?action=download";
	form.submit();
}
	
//-->
</script>

<form action="<%=context%>/wall.do" method="post">

书名：<input type="text" name="bookName" value="<%=bookName%>" />
<input type="submit" value="搜索" />

<br><br>

<input type="button" value="下载所有txt" onclick="downloadAllTxt()" />
<input type="button" value="下载所有chm" onclick="downloadAllChm()" />
<input type="button" value="下载" onclick="downloadChm()" />

<hr>

<table border="1">

	<tr>
		<td><input type="checkbox" name="all" onclick="selectAll(this)" /></td>
		<td>书名</td>
		<td>作者</td>
		<td>txt下载</td>
		<td>chm下载</td>
		<td>本地打开</td>
	</tr>
	
	<%for(int i = 0;i<bookList.size();i++){
		Book book = (Book)bookList.get(i);
	%>
		<tr>
			<td><input type="checkbox" name="fid" value="<%=book.getBookId()%>" /></td>
			<td><%=book.getName()%></td>
			<td><%=book.getAuthor()%></td>
			<td><a href="<%=book.getTxtUrl()%>">下载</a></td>
			<td><a href="<%=book.getChmUrl()%>">下载</a></td>
			<td><a href="<%=context%>/wall.do?action=downloadFromLocal&bookId=<%=book.getBookId()%>">打开</a></td>
		</tr>
	<%}%>

</table>

</form>